package com.xjh.serverinspect.util;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * command-conf.xml的配置类
 * </p>
 *
 * @author xujinghui
 * @since 2024-10-15
 */
@Setter
@Getter
@XmlRootElement(name = "config")
@XmlAccessorType(XmlAccessType.FIELD)
public class CommandConf {

    @XmlElementWrapper(name = "servers") // 这个注解等于在最外面再包一层
    @XmlElement(name = "server")
    private List<Server> servers;

    private Shell shell;

    private Sql sql;

    @Setter
    @Getter
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Server {
        private String host;
        private Shell shell;
        private Sql sql;
    }

    @Setter
    @Getter
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Shell {
        private Integer port;
        private String username;
        private String password;
        @XmlElementWrapper(name = "commands")
        @XmlElement(name = "command")
        private List<Command> commands;
    }

    @Setter
    @Getter
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Sql {
        private Integer port;
        private String username;
        private String password;
        private String database;
        @XmlElementWrapper(name = "commands")
        @XmlElement(name = "command")
        private List<Command> commands;
    }

    @Setter
    @Getter
    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Command {
        @XmlValue
        private String script;
        @XmlAttribute(name = "description")
        private String description;
        @XmlAttribute(name = "resultType")
        private String resultType;
    }

}
